<template>
	<view class="content">
		<view class="order-item" v-for="(item,index) in orderList" :key="index">
			<view class="seller-name">{{item.terminalName}}</view>
			<view class="pay-info">
				<view class="pay-status" v-if="item.orderStatus == 0">未支付</view>
				<view class="pay-status" v-if="item.orderStatus == 4">已退款</view>
				<view class="pay-status" v-if="(item.orderStatus != 0) && item.orderStatus != 4">已支付</view>
				<view class="pay-time">{{item.createTime}}</view>
			</view>
			<view class="goods-item" v-for="(itemGoods,indexGoods) in item.orderDetailList" :key="indexGoods">
				<view class="line"></view>
				<view class="detail">
					<image :src="itemGoods.thumbUrl"></image>
					<view class="info">
						<view class="name">{{itemGoods.name}}</view>
						<view class="price"><span style="font-size: 24rpx;">￥</span>{{itemGoods.salePrice}}</view>
					</view>
					<view class="num">x{{itemGoods.totalNum}}</view>
				</view>
			</view>
		
			<view class="line"></view>
			<view class="price-info">
				<!-- <view class="price">总价￥{{item.goodsAmount}} 优惠￥{{item.couponAmount}}</view> -->
				<view class="total">总计：￥{{item.goodsAmount}}</view>
			</view>
			<view class="action" v-if="item.orderStatus == 0">
				<view class="pay" @click="gotoPay(item)">立即支付</view>
			</view>
		</view>
		<view v-if="orderList.length == 0" class="nodata">暂无订单~</view>
	</view>
</template>

<script>
	import {
		departId
	} from '../../config'
	export default {
		data() {
			return {
				orderList:[],
				openId:'',
				pageNo:1,
				pageSize:20,
			}
		},
		onShow() {
			this.openId = uni.getStorageSync('lianghopenid');
			if(this.openId){
				this.getList();
			}else{
				let that = this;
				uni.login({
					success(loginRes) {
						console.log(loginRes)
						that.code = loginRes.code
						that.$api.miniCodeLogin({params:{departId:departId,code:loginRes.code}}).then(res =>{
							that.openId = res.openId;
							uni.setStorageSync('lianghopenid',that.openId);
							that.getList();
						});
					},
					fail(res){
						console.log('fail');
						console.log(res)
					}
				})
			}
		},
		methods: {
			getList(){
				this.$api.findOrderByTerminalNo({params:{openId:this.openId,orderStatus:1,pageNo:this.pageNo,pageSize:this.pageSize}}).then(res =>{
					this.orderList = res.data.page.records
				})
			},
			gotoPay(item){
				
			}
		}
	}
</script>

<style lang="less">
page{
		background-color: #f7f7f7;
	}
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		.order-item{
			display: flex;
			flex-direction: column;
			background: #FFFFFF;
			border-radius: 6rpx;
			width: 690rpx;
			position: relative;
			margin-top: 10rpx;
			
			.seller-name{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;
				margin-top: 34rpx;
				margin-left: 32rpx;
				margin-bottom: 34rpx;
			}
			.pay-info{
				position: absolute;
				right: 32rpx;
				top: 27rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				.pay-status{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #DC564A;
				}
				.pay-time{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #333;
					
				}
			}
			
			.goods-item{
				.line{
					width: 626rpx;
					height: 1px;
					background-color: #E9E9E9;
					margin-left: 32rpx;
				}
				
				
				.detail{
					display: flex;
					flex-direction: row;
					height: 210rpx;
					align-items: center;
					position: relative;
					.info{
						display: flex;
						flex-direction: column;
						margin-left: 30rpx;
					}
					.name{
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 28rpx;
						color: #333333;
					}
					.price{
						font-family: DINAlternate, DINAlternate;
						font-weight: bold;
						font-size: 36rpx;
						color: #333333;
						margin-top: 76rpx;
					}
					.num{
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 28rpx;
						position: absolute;
						right: 40rpx;
						bottom: 23rpx;
					}
					image{
						margin-left: 46rpx;
						width: 120rpx;
						height: 120rpx;
					}
				}
			}
			.line{
				width: 626rpx;
				height: 1px;
				background-color: #E9E9E9;
				margin-left: 32rpx;
			}
			.price-info{
				height: 100rpx;
				display: flex;
				flex-direction: row;
				align-items:center;
				justify-content: flex-end;
				width: 100%;
				
				.price{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #999999;
					margin-right: 20rpx;
				}
				.total{
					font-family: DINAlternate, DINAlternate;
					font-weight: bold;
					font-size: 36rpx;
					color: #333333;
					margin-right: 33rpx;
				}
			}
			.action{
				height: 100rpx;
				width: 100%;
				flex-direction: row;
				align-items:center;
				justify-content: flex-end;
				display: flex;
				.pay{
					width: 174rpx;
					height: 74rpx;
					background: #DC564A;
					border-radius: 39rpx;
					line-height: 74rpx;
					text-align: center;
					font-family: PingFang-SC, PingFang-SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					margin-right: 33rpx;
				}
			}
		}
		.nodata{
			width: 100%;
			height: 1000rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
		
		}
	}
</style>
